package com.explore.demo.service.impl;

import com.explore.demo.common.ServerResponse;
import com.explore.demo.service.FileUploadService;
import com.explore.demo.utils.FileUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

/**
 * @author gaolainan
 */
@Service
public class FileUploadServiceImpl implements FileUploadService
{

    /**
     * 打印日志文件
     */
    private final Logger logger = LoggerFactory.getLogger(FileUploadServiceImpl.class);

    @Value("{file.uploadUrl}")
    private String uploadPath;

    @Resource
    private FileUtils fileUtils;

    @Override
    public ServerResponse upload(MultipartFile file)
    {
        logger.info("地址的为"+ uploadPath);
        // 在这里应该是 存到对应的 用户的简历附件地址
        String desc = fileUtils.saveFile(file);
        if (desc == null){
            return ServerResponse.createBySuccessMessage("上传失败",2000,null);
        }
        return ServerResponse.createBySuccessMessage("上传成功",200,null);
    }



}
